package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Visitor;
import com.zzyl.nursing.service.IVisitorService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 来访登记Controller
 * 
 * @author ruoyi
 * @date 2025-05-09
 */
@RestController
@RequestMapping("/nursing/visitor")
@Api(tags = "来访登记的接口")
public class VisitorController extends BaseController
{
    @Autowired
    private IVisitorService visitorService;

    /**
     * 查询来访登记列表
     */
    @ApiOperation("查询来访登记列表")
    @PreAuthorize("@ss.hasPermi('nursing:visitor:list')")
    @GetMapping("/list")
    public TableDataInfo list(Visitor visitor)
    {
        startPage();
        List<Visitor> list = visitorService.selectVisitorList(visitor);
        return getDataTable(list);
    }

    /**
     * 导出来访登记列表
     */
    @ApiOperation("导出来访登记列表")
    @PreAuthorize("@ss.hasPermi('nursing:visitor:export')")
    @Log(title = "来访登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Visitor visitor)
    {
        List<Visitor> list = visitorService.selectVisitorList(visitor);
        ExcelUtil<Visitor> util = new ExcelUtil<Visitor>(Visitor.class);
        util.exportExcel(response, list, "来访登记数据");
    }

    /**
     * 获取来访登记详细信息
     */
    @ApiOperation("获取来访登记详细信息")
    @PreAuthorize("@ss.hasPermi('nursing:visitor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(value = "来访登记ID", required = true)
            @PathVariable("id") Long id)
    {
        return success(visitorService.selectVisitorById(id));
    }

    /**
     * 新增来访登记
     */
    @ApiOperation("新增来访登记")
    @PreAuthorize("@ss.hasPermi('nursing:visitor:add')")
    @Log(title = "来访登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(value = "来访登记实体")
            @RequestBody Visitor visitor)
    {
        return toAjax(visitorService.insertVisitor(visitor));
    }

    /**
     * 修改来访登记
     */
    @ApiOperation("修改来访登记")
    @PreAuthorize("@ss.hasPermi('nursing:visitor:edit')")
    @Log(title = "来访登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(value = "来访登记实体")
            @RequestBody Visitor visitor)
    {
        return toAjax(visitorService.updateVisitor(visitor));
    }

    /**
     * 删除来访登记
     */
    @ApiOperation("删除来访登记")
    @PreAuthorize("@ss.hasPermi('nursing:visitor:remove')")
    @Log(title = "来访登记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(visitorService.deleteVisitorByIds(ids));
    }
}
